package com.situ.mall.product.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.product.Category;
import com.situ.mall.product.pojo.vo.Category23VO;
import com.situ.mall.product.pojo.vo.CategoryVO;
import com.situ.mall.product.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品分类 前端控制器
 * </p>
 *
 * @author Sun Huijuan
 * @since 2024-10-09
 */
@RestController
@RequestMapping("/product/category")
public class CategoryController {

	@Autowired
	private ICategoryService categoryService;
	
	@GetMapping("/selectCategoryTree")
	public Result<List<CategoryVO>> selectCategoryTree() {
		List<CategoryVO> list = categoryService.selectCategoryTree();
		return Result.ok(list);
	}
	
	@RequestMapping("/selectByParentId/{id}")
	public Result<List<CategoryVO>> selectByParentId(@PathVariable Long id) {
		List<CategoryVO> list=categoryService.selectByParentId(id);
		return Result.ok(list);
	}
	
	@GetMapping("/selectAllCategory3")
	public Result<List<Category>> selectAllCategory3() {
		List<Category> list=categoryService.selectAllCategory3();
		return Result.ok(list);
	}
	
	//查二三级分类
	@GetMapping("/selectAllCategory23")
	public Result<List<Category23VO>> selectAllCategory23() {
		List<Category23VO> list=categoryService.selectAllCategory23();
		System.out.println("======"+list);
		return Result.ok(list);
	}
	
	@PutMapping("/update")
	public Result updateCategory(@RequestBody Category category) {
		categoryService.update(category);
		return Result.ok("修改成功！");
	}
	
}

